package game.core
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import game.manager.XMLManager;
	
	public class XMLLoader extends EventDispatcher
	{
		private var path:String;
		
		public function XMLLoader(path:String)
		{
			this.path = path;
		}
		
		public function execute():void {
			var loader:URLLoader = new URLLoader();
			var request:URLRequest = new URLRequest(this.path);
			loader.addEventListener(Event.COMPLETE,completeHanlder);
			loader.load(request);
		}
		
		private function completeHanlder(event:Event):void {
			var data:String = URLLoader(event.currentTarget).data;
			var xml:XML = new XML(data);// 先暂时这么处理一下
			XMLManager.instance.items = xml;
			this.dispatchEvent(event);// 广播一个完成的事件
		}
	}
}